#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QRandomGenerator>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setWindowTitle("Infy模块控制系统_V2.0");
    Init();

    refreshTimer = startTimer(50, Qt::CoarseTimer);
    sampleTimer = startTimer(50, Qt::CoarseTimer);

    // 创建一个定时器，设置定时时间为3秒
    timer = new QTimer(this);
    //timer->setInterval(5000);

    customPlotModule_V_A();

    QStringList strList1;
    strList1<<"模块串联"<<"模块并联";
    ui->comboBox_all->addItems(strList1);

    //创建线程对象
    QThread* task2 = new QThread;               //task2:CAN操作
    //创建任务对象
    canThread* can = new canThread;
    //放入多线程
    can->moveToThread(task2);
    //启动线程
    task2->start();

    thread_1 = new QThread;
    recharge = new RechargeThread;
    recharge->moveToThread(thread_1);
    thread_1->start();

    QThread* thread2 =new QThread;
    MyData* data = new MyData;
    //data = new MyData;
    data->moveToThread(thread2);
    thread2->start();
    //信号槽释放资源
    connect(this,&MainWindow::destroyed,this,[=](){
        //释放创建的子线程对象
        thread2->wait();//先wait 后quit
        thread2->quit();
        thread2->deleteLater();
        //释放创建的任务对象
        data->deleteLater();
    });

    timer_setGroup = new QTimer(this);
    timer_setmodule = new QTimer(this);
    timer_setGroup->setInterval(1000);//设置定时器间隔1秒
    timer_setmodule->setInterval(1000);
    //信号槽
    connect(timer_setGroup,SIGNAL(timeout()),this,SLOT(SendData_go()));
    connect(timer_setmodule,SIGNAL(timeout()),this,SLOT(SendData_group()));


    //信号槽
    connect(recharge,&RechargeThread::sig_module_set1,this,&MainWindow::Module_set_Series);
    connect(recharge,&RechargeThread::sig_module_set2,this,&MainWindow::Module_set_Series);
    connect(recharge,&RechargeThread::sig_module_set3,this,&MainWindow::Module_set_Series);
    connect(recharge,&RechargeThread::sig_module_set4,this,&MainWindow::Module_set_Series);
    connect(recharge,&RechargeThread::sig_module_set5,this,&MainWindow::Module_set_Series);
    connect(recharge,&RechargeThread::sig_module1_state,this,&MainWindow::Module1_state);
    connect(recharge,&RechargeThread::sig_module2_state,this,&MainWindow::Module2_state);
    connect(recharge,&RechargeThread::sig_module3_state,this,&MainWindow::Module3_state);
    connect(recharge,&RechargeThread::sig_module4_state,this,&MainWindow::Module4_state);
    connect(recharge,&RechargeThread::sig_set1,data,&MyData::writeModule_set_File_05);
    connect(recharge,&RechargeThread::sig_module_set5,data,&MyData::writeModule_set_File_06);
    connect(this,&MainWindow::sig_module1_bug,data,&MyData::writeModuleFile_01);
    connect(this,&MainWindow::sig_module2_bug,data,&MyData::writeModuleFile_02);
    connect(this,&MainWindow::sig_module3_bug,data,&MyData::writeModuleFile_03);
    connect(this,&MainWindow::sig_module4_bug,data,&MyData::writeModuleFile_04);
    connect(recharge,&RechargeThread::sig_system_V_A,this,&MainWindow::System_V_A);
    connect(recharge,&RechargeThread::sig_module1_V_A,this,&MainWindow::Module1_V_A);
    connect(recharge,&RechargeThread::sig_module2_V_A,this,&MainWindow::Module2_V_A);
    connect(recharge,&RechargeThread::sig_module3_V_A,this,&MainWindow::Module3_V_A);
    connect(recharge,&RechargeThread::sig_module4_V_A,this,&MainWindow::Module4_V_A);
    connect(recharge,&RechargeThread::sig_system_moduleNum,this,&MainWindow::System_ModuleNum);
    connect(recharge,&RechargeThread::sig_ceg1,this,&MainWindow::CEG1_View);
    connect(recharge,&RechargeThread::sig_ceg2,this,&MainWindow::CEG2_View);
    connect(recharge,&RechargeThread::sig_ceg3,this,&MainWindow::CEG3_View);
    connect(recharge,&RechargeThread::sig_ceg4,this,&MainWindow::CEG4_View);

    connect(this,&MainWindow::sig_bug1,this,&MainWindow::Bug1);
    connect(this,&MainWindow::sig_bug2,this,&MainWindow::Bug2);
    connect(this,&MainWindow::sig_bug3,this,&MainWindow::Bug3);
    connect(this,&MainWindow::sig_bug4,this,&MainWindow::Bug4);
    connect(this,&MainWindow::sig_bug5,this,&MainWindow::Bug5);
    connect(this,&MainWindow::sig_bug6,this,&MainWindow::Bug6);
    connect(this,&MainWindow::sig_bug7,this,&MainWindow::Bug7);
    connect(this,&MainWindow::sig_bug8,this,&MainWindow::Bug8);
    connect(this,&MainWindow::sig_bug9,this,&MainWindow::Bug9);
    connect(this,&MainWindow::sig_bug10,this,&MainWindow::Bug10);
    connect(this,&MainWindow::sig_bug11,this,&MainWindow::Bug11);
    connect(this,&MainWindow::sig_bug12,this,&MainWindow::Bug12);
    connect(this,&MainWindow::sig_bug13,this,&MainWindow::Bug13);
    connect(this,&MainWindow::sig_bug14,this,&MainWindow::Bug14);
    connect(this,&MainWindow::sig_bug15,this,&MainWindow::Bug15);
    connect(this,&MainWindow::sig_bugAll,this,&MainWindow::Bug_All);

    connect(this,&MainWindow::SIGtocancon,can,&canThread::openCan);  //点击启动CAN按钮打开CAN
    connect(this,&MainWindow::SIGtocansto,can,&canThread::stopCan);  //点击启动CAN按钮关闭CAN
    connect(this,&MainWindow::SIGtocansen,can,&canThread::sendData); //点击发送按钮，将框内ID和Data数据送到CAN发送函数
    connect(can,&canThread::SIGcanclosuc,this,&MainWindow::Signal_open);
    connect(can,&canThread::SIGcanopefai,this,&MainWindow::Signal_stop);
    connect(can,&canThread::dataStart,this,&MainWindow::Signal_receive);
    connect(can,&canThread::dataCan,recharge,&RechargeThread::data);
    //connect(can,&canThread::SendCan,ui->textEdit,&QTextEdit::append);  //显示CAN接收数据
    m_Timer.setTimerType(Qt::PreciseTimer);
    connect(&m_Timer,&QTimer::timeout,this,[=]()
    {
        SendData_go();//设置系统各模块为拨号模式
        //SendData_group();//设置系统各模块组号为1
    });
    m_Timer.start(1000);
    Timer.setTimerType(Qt::PreciseTimer);
    connect(&Timer,&QTimer::timeout,this,[=]()
    {
        Vist_System_VA();
        Vist_Module_VA();
        Vist__VA1();
        Vist_System_state();
        Vist_state1();
        Vist_System_module_Num();
        Vist_CEG1();
        Vist_CEG2();
        Vist_CEG3();
        Vist_CEG4();
    });
    Timer.start(100);
    on_btnCAN_clicked();
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::Init()
{
//    this->setProperty("form", true);
//    this->setProperty("canMove", true);
//    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);

    ui->lightButton_TX->setGray();
    ui->lightButton_start->setGray();
    ui->lightButton_Walkin->setGray();
    ui->lightButton_fault->setGray();
    ui->lightButton_W1->setGray();
    ui->lightButton_sleep1->setGray();
    ui->lightButton_start_3->setGray();
    ui->lightButton_Walkin_2->setGray();
    ui->lightButton_fault_2->setGray();
    ui->lightButton_W2->setGray();
    ui->lightButton_sleep2->setGray();
    ui->lightButton_start_4->setGray();
    ui->lightButton_Walkin_3->setGray();
    ui->lightButton_fault_3->setGray();
    ui->lightButton_W3->setGray();
    ui->lightButton_sleep3->setGray();
    ui->lightButton_start_5->setGray();
    ui->lightButton_Walkin_4->setGray();
    ui->lightButton_fault_4->setGray();
    ui->lightButton_W4->setGray();
    ui->lightButton_sleep4->setGray();

    ui->lightButton_in_guoya->setGray();
    ui->lightButton_out_guoya->setGray();
    ui->lightButton_in_qianya->setGray();
    ui->lightButton_guowen->setGray();
    ui->lightButton_fengshan->setGray();
    ui->lightButton_mokuai->setGray();
    ui->lightButton_out_duanlu->setGray();
    ui->lightButton_in_muxian->setGray();
    ui->lightButton_fangdian->setGray();
    ui->lightButton_tongxin->setGray();
    ui->lightButton_tongxin_fault->setGray();
    ui->lightButton_ID->setGray();
    ui->lightButton_junliu->setGray();
    ui->lightButton_sanxaing_quexiang->setGray();
    ui->lightButton_sanxiang_bupingheng->setGray();


    ui->lineEdit_system_V->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_system_V->setReadOnly(true);
    ui->lineEdit_system_V->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_system_A->setReadOnly(true);
    ui->lineEdit_system_A->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module1_A->setReadOnly(true);
    ui->lineEdit_module1_A->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module1_V->setReadOnly(true);
    ui->lineEdit_module1_V->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module1_tem->setReadOnly(true);
    ui->lineEdit_module1_tem->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module2_A->setReadOnly(true);
    ui->lineEdit_module2_A->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module2_V->setReadOnly(true);
    ui->lineEdit_module2_V->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module2_tem->setReadOnly(true);
    ui->lineEdit_module2_tem->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module3_A->setReadOnly(true);
    ui->lineEdit_module3_A->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module3_V->setReadOnly(true);
    ui->lineEdit_module3_V->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module3_tem->setReadOnly(true);
    ui->lineEdit_module3_tem->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module4_A->setReadOnly(true);
    ui->lineEdit_module4_A->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module4_V->setReadOnly(true);
    ui->lineEdit_module4_V->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_module4_tem->setReadOnly(true);
    ui->lineEdit_module4_tem->setFocusPolicy(Qt::ClickFocus);
    ui->cc1state_le_8->setReadOnly(true);
    ui->cc1state_le_8->setFocusPolicy(Qt::ClickFocus);
    ui->cc1state_le_4->setReadOnly(true);
    ui->cc1state_le_4->setFocusPolicy(Qt::ClickFocus);
    ui->cc1state_le_5->setReadOnly(true);
    ui->cc1state_le_5->setFocusPolicy(Qt::ClickFocus);

    ui->btnStart->setStyleSheet("QPushButton{background-color:#55aaff;"//背景红色
                                   "border-radius: 10px;}"
                                   "QPushButton:hover{"
                                   "background-color:#55ffff;"
                                   "color:white;"
                                   "}");
    ui->btnStop->setStyleSheet("QPushButton{background-color:#ff557f;"//背景红色
                               "border-radius: 10px;}"
                               "QPushButton:hover{"
                               "background-color:#ffaaff;"
                               "color:white;"
                               "}");
    ui->btnWalkin_start->setStyleSheet("QPushButton{background-color:#55ff00;"//背景红色
                               "border-radius: 10px;}"
                               "QPushButton:hover{"
                               "background-color:#55ff7f;"
                               "color:white;"
                               "}");
    ui->btnWalkin_stop->setStyleSheet("QPushButton{background-color:#ffaa00;"//背景红色
                               "border-radius: 10px;}"
                               "QPushButton:hover{"
                               "background-color:#ffaa7f;"
                               "color:white;"
                               "}");
//    ui->btnCAN->setStyleSheet("QPushButton{background-color:#9933fa;"//背景红色
//                               "border-radius: 10px;}"
//                               "QPushButton:hover{"
//                               "background-color:#da70d6;"
//                               "color:white;"
//                               "}");
//    ui->btnSet->setStyleSheet("QPushButton{background-color:rgb(20,196,188);"//背景蓝色
//                               "border-radius: 10px;}"
//                               "QPushButton:hover{"
//                               "background-color:#40E0D0;"
//                               "color:white;"
//                               "}");
//    ui->btnLightGreen->setStyleSheet("QPushButton{background-color:rgb(20,196,188);"//背景蓝色
//                               "border-radius: 10px;}"
//                               "QPushButton:hover{"
//                               "background-color:#40E0D0;"
//                               "color:white;"
//                               "}");


    ui->cc1state_le_8->setStyleSheet("font: 25 16pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:0px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(20,196,188);border-radius:5px;");//边框粗细-颜色-圆角设置
    ui->cc1state_le_2->setStyleSheet("font: 25 13pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:0px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->cc1state_le_3->setStyleSheet("font: 25 13pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:0px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->cc1state_le_4->setStyleSheet("font: 25 13pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:0px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->cc1state_le_5->setStyleSheet("font: 25 13pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:0px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_system_V->setAlignment(Qt::AlignCenter); // 设置文本居中对齐
    ui->lineEdit_system_A->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module1_A->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module1_V->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module1_tem->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module2_A->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module2_V->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module2_tem->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module3_A->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module3_V->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module3_tem->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module4_A->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module4_V->setAlignment(Qt::AlignCenter);
    ui->lineEdit_module4_tem->setAlignment(Qt::AlignCenter);
}

void MainWindow::timerEvent(QTimerEvent *event)
{
    Q_UNUSED(event);
    double key = QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000.0;

    if(event->timerId() == refreshTimer)
    {
        double xHigh = key - 0.5;
        plot->xAxis->setRange(xHigh - plot->xAxis->range().size(),xHigh);
        plot->replot();

    }

    if(event->timerId() == sampleTimer) //30ms
    {
        plot->graph(0)->addData(key, V1);
        plot->graph(1)->addData(key, V2);
        plot->graph(2)->addData(key, V3);
        plot->graph(3)->addData(key, V4);

        plot->graph(4)->addData(key, A1);
        plot->graph(5)->addData(key, A2);
        plot->graph(6)->addData(key, A3);
        plot->graph(7)->addData(key, A4);

        //ui->lineEdit_system_A->setText(QString::number(sys_cur)+"A");
        //ui->lineEdit_system_V->setText(QString::number(sys_vol)+"V");

//        ui->lineEdit_module1_A->setText(QString::number(V1)+"A");
//        ui->lineEdit_module1_V->setText(QString::number(A1)+"V");

//        ui->lineEdit_module2_A->setText(QString::number(V2)+"A");
//        ui->lineEdit_module2_V->setText(QString::number(A2)+"V");

//        ui->lineEdit_module3_A->setText(QString::number(V3)+"A");
//        ui->lineEdit_module3_V->setText(QString::number(A3)+"V");

//        ui->lineEdit_module4_A->setText(QString::number(V4)+"A");
//        ui->lineEdit_module4_V->setText(QString::number(A4)+"V");
    }
    plot->graph(0)->removeDataBefore(key - 5000);
    plot->graph(1)->removeDataBefore(key - 5000);
    plot->graph(2)->removeDataBefore(key - 5000);
    plot->graph(3)->removeDataBefore(key - 5000);

    plot->graph(4)->removeDataBefore(key - 5000);
    plot->graph(5)->removeDataBefore(key - 5000);
    plot->graph(6)->removeDataBefore(key - 5000);
    plot->graph(7)->removeDataBefore(key - 5000);

}

void MainWindow::System_ModuleNum(QString da1)
{
    QString data = da1.mid(4,2);
    int num = data.toInt(0,16);//16进制转10进制
    sys_num = num;
    ui->cc1state_le_8->setText(QString::number(num));
    sys_set = set1+set2+set3+set4;
}

void MainWindow::System_V_A(QString da1)
{
    //QString data = "00030D40";
    QString dataV = da1.mid(0,8);//电压
    QString dataA = da1.mid(8,8);//电流值
    uint vol = dataV.toUInt(nullptr, 16);//16进制转10进制
    uint cur = dataA.toUInt(nullptr, 16);
    V_sys = *(float*)&vol;
    A_sys = *(float*)&cur;
    ui->lineEdit_system_A->setText(QString::number(A_sys,'f', 2)+"A");
    ui->lineEdit_system_V->setText(QString::number(V_sys,'f', 2)+"V");
//    QString str="41a40000";
//    int hex = str.toUInt(0, 16);

    //qDebug()<<value;
    //V_sys = vol;
    //A_sys = cur;
}

void MainWindow::Module1_V_A(QString da1)
{
    QString dataV = da1.mid(0,8);//电压
    QString dataA = da1.mid(8,8);//电流值
    uint vol = dataV.toUInt(nullptr, 16);//16进制转10进制
    uint cur = dataA.toUInt(nullptr, 16);
    V1 = *(float*)&vol;
    A1 = *(float*)&cur;
    ui->lineEdit_module1_A->setText(QString::number(A1,'f', 2)+"A");
    ui->lineEdit_module1_V->setText(QString::number(V1,'f', 2)+"V");
    //V1 = vol;
    //A1 = cur;
//    sys_vol = V1+V2;
//    sys_cur = A1+A3;
//    ui->lineEdit_system_A->setText(QString::number(sys_cur)+"A");
//    ui->lineEdit_system_V->setText(QString::number(sys_vol)+"V");
}

void MainWindow::Module2_V_A(QString da1)
{
    QString dataV = da1.mid(0,8);//电压
    QString dataA = da1.mid(8,8);//电流值
    uint vol = dataV.toUInt(nullptr, 16);//16进制转10进制
    uint cur = dataA.toUInt(nullptr, 16);
    V2 = *(float*)&vol;
    A2 = *(float*)&cur;
    ui->lineEdit_module2_A->setText(QString::number(A2,'f', 2)+"A");
    ui->lineEdit_module2_V->setText(QString::number(V2,'f', 2)+"V");
    //V2 = vol;
    //A2 = cur;
//    sys_vol = V1+V2;
    //ui->lineEdit_system_V->setText(QString::number(sys_vol)+"V");
}

void MainWindow::Module3_V_A(QString da1)
{
    QString dataV = da1.mid(0,8);//电压
    QString dataA = da1.mid(8,8);//电流值
    uint vol = dataV.toUInt(nullptr, 16);//16进制转10进制
    uint cur = dataA.toUInt(nullptr, 16);
    V3 = *(float*)&vol;
    A3 = *(float*)&cur;
    ui->lineEdit_module3_A->setText(QString::number(A3,'f', 2)+"A");
    ui->lineEdit_module3_V->setText(QString::number(V3,'f', 2)+"V");
    //V3 = vol;
    //A3 = cur;
//    sys_cur = A1+A3;
    //ui->lineEdit_system_A->setText(QString::number(sys_cur)+"A");
}

void MainWindow::Module4_V_A(QString da1)
{
    QString dataV = da1.mid(0,8);//电压
    QString dataA = da1.mid(8,8);//电流值
    uint vol = dataV.toUInt(nullptr, 16);//16进制转10进制
    uint cur = dataA.toUInt(nullptr, 16);
    V4 = *(float*)&vol;
    A4 = *(float*)&cur;
    ui->lineEdit_module4_A->setText(QString::number(A4,'f', 2)+"A");
    ui->lineEdit_module4_V->setText(QString::number(V4,'f', 2)+"V");
    //V4 = vol;
    //A4 = cur;
}

void MainWindow::Module1_state(QString da1)
{
    QString byte0 = da1.mid(8,2);
    int tem = byte0.toInt(0,16);
    ui->lineEdit_module1_tem->setText(QString::number(tem)+"℃");
    QString byte1 = QString("%1").arg(da1.mid(10,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态2
    QString byte2 = QString("%1").arg(da1.mid(12,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态1
    QString byte3 = QString("%1").arg(da1.mid(14,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte1_0 = byte1.mid(0,1);//模块 PFC 侧处于关机状态
    QString byte1_1 = byte1.mid(1,1);//输入过压告警
    QString byte1_2 = byte1.mid(2,1);//输入欠压告警
    QString byte1_3 = byte1.mid(3,1);//三相输入不平衡告警
    QString byte1_4 = byte1.mid(4,1);//三相输入缺相告警
    QString byte1_5 = byte1.mid(5,1);//模块严重不均流
    QString byte1_6 = byte1.mid(6,1);//模块 ID 重复
    QString byte1_7 = byte1.mid(7,1);//模块处于限功率状态

    QString byte2_0 = byte2.mid(0,1);//模块通信中断告警
    QString byte2_1 = byte2.mid(1,1);//WALK-IN 使能
    QString byte2_2 = byte2.mid(2,1);//输出过压告警
    QString byte2_3 = byte2.mid(3,1);//过温告警
    QString byte2_4 = byte2.mid(4,1);//风扇故障告警
    QString byte2_5 = byte2.mid(5,1);//模块保护告警
    QString byte2_6 = byte2.mid(6,1);//模块故障告警
    QString byte2_7 = byte2.mid(7,1);//模块 DC 侧处于关机状态

    QString byte3_2 = byte3.mid(2,1);//模块放电异常
    QString byte3_3 = byte3.mid(3,1);//模块休眠
    QString byte3_4 = byte3.mid(4,1);//输入或母线异常
    QString byte3_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte3_7 = byte3.mid(7,1);//输出短路

    //输入过压告警
    if(byte1_1 == "1")
    {
        bug1_1 = byte1_1;
        BUG1 = bug1_1+bug1_2+bug1_3+bug1_4;
        emit sig_bug1(BUG1);
    }
    else if(byte1_1 == "0")
    {
        bug1_1 = byte1_1;
        BUG1 = bug1_1+bug1_2+bug1_3+bug1_4;
        emit sig_bug1(BUG1);
    }
    //输入欠压告警
    if(byte1_2 == "1")
    {
        bug2_1 = byte1_2;
        BUG2 = bug2_1+bug2_2+bug2_3+bug2_4;
        emit sig_bug2(BUG2);
    }
    else if(byte1_2 == "0")
    {
        bug2_1 = byte1_2;
        BUG2 = bug2_1+bug2_2+bug2_3+bug2_4;
        emit sig_bug2(BUG2);
    }
    //三相输入不平衡告警
    if(byte1_3 == "1")
    {
        bug3_1 = byte1_3;
        BUG3 = bug3_1+bug3_2+bug3_3+bug3_4;
        emit sig_bug3(BUG3);
    }
    else if(byte1_3 == "0")
    {
        bug3_1 = byte1_3;
        BUG3 = bug3_1+bug3_2+bug3_3+bug3_4;
        emit sig_bug3(BUG3);
    }
    //三相输入缺相告警
    if(byte1_4 == "1")
    {
        bug4_1 = byte1_4;
        BUG4 = bug4_1+bug4_2+bug4_3+bug4_4;
        emit sig_bug4(BUG4);
    }
    else if(byte1_4 == "0")
    {
        bug4_1 = byte1_4;
        BUG4 = bug4_1+bug4_2+bug4_3+bug4_4;
        emit sig_bug4(BUG4);
    }
    //模块严重不均流
    if(byte1_5 == "1")
    {
        bug5_1 = byte1_5;
        BUG5 = bug5_1+bug5_2+bug5_3+bug5_4;
        emit sig_bug5(BUG5);
    }
    else if(byte1_5 == "0")
    {
        bug5_1 = byte1_5;
        BUG5 = bug5_1+bug5_2+bug5_3+bug5_4;
        emit sig_bug5(BUG5);
    }
    //模块 ID 重复
    if(byte1_6 == "1")
    {
        bug6_1 = byte1_6;
        BUG6 = bug6_1+bug6_2+bug6_3+bug6_4;
        emit sig_bug6(BUG6);
    }
    else if(byte1_6 == "0")
    {
        bug6_1 = byte1_6;
        BUG6 = bug6_1+bug6_2+bug6_3+bug6_4;
        emit sig_bug6(BUG6);
    }
    //模块通信中断告警
    if(byte2_0 == "1")
    {
        bug7_1 = byte2_0;
        BUG7 = bug7_1+bug7_2+bug7_3+bug7_4;
        emit sig_bug7(BUG7);
    }
    else if(byte2_0 == "0")
    {
        bug7_1 = byte2_0;
        BUG7 = bug7_1+bug7_2+bug7_3+bug7_4;
        emit sig_bug7(BUG7);
    }
    //输出过压告警
    if(byte2_2 == "1")
    {
        bug8_1 = byte2_2;
        BUG8 = bug8_1+bug8_2+bug8_3+bug8_4;
        emit sig_bug8(BUG8);
    }
    else if(byte2_2 == "0")
    {
        bug8_1 = byte2_2;
        BUG8 = bug8_1+bug8_2+bug8_3+bug8_4;
        emit sig_bug8(BUG8);
    }
    //过温告警
    if(byte2_3 == "1")
    {
        bug9_1 = byte2_3;
        BUG9 = bug9_1+bug9_2+bug9_3+bug9_4;
        emit sig_bug9(BUG9);
    }
    else if(byte2_3 == "0")
    {
        bug9_1 = byte2_3;
        BUG9 = bug9_1+bug9_2+bug9_3+bug9_4;
        emit sig_bug9(BUG9);
    }
    //风扇故障告警
    if(byte2_4 == "1")
    {
        bug10_1 = byte2_4;
        BUG10 = bug10_1+bug10_2+bug10_3+bug10_4;
        emit sig_bug10(BUG10);
    }
    else if(byte2_4 == "0")
    {
        bug10_1 = byte2_4;
        BUG10 = bug10_1+bug10_2+bug10_3+bug10_4;
        emit sig_bug10(BUG10);
    }
    //模块保护告警
    if(byte2_5 == "1")
    {
        bug11_1 = byte2_5;
        BUG11 = bug11_1+bug11_2+bug11_3+bug11_4;
        emit sig_bug11(BUG11);
    }
    else if(byte2_5 == "0")
    {
        bug11_1 = byte2_5;
        BUG11 = bug11_1+bug11_2+bug11_3+bug11_4;
        emit sig_bug11(BUG11);
    }
    //模块放电异常
    if(byte3_2 == "1")
    {
        bug12_1 = byte3_2;
        BUG12 = bug12_1+bug12_2+bug12_3+bug12_4;
        emit sig_bug12(BUG12);
    }
    else if(byte3_2 == "0")
    {
        bug12_1 = byte3_2;
        BUG12 = bug12_1+bug12_2+bug12_3+bug12_4;
        emit sig_bug12(BUG12);
    }
    //输入或母线异常
    if(byte3_4 == "1")
    {
        bug13_1 = byte3_4;
        BUG13 = bug13_1+bug13_2+bug13_3+bug13_4;
        emit sig_bug13(BUG13);
    }
    else if(byte3_4 == "0")
    {
        bug13_1 = byte3_4;
        BUG13 = bug13_1+bug13_2+bug13_3+bug13_4;
        emit sig_bug13(BUG13);
    }
    //模块内部通信故障
    if(byte3_5 == "1")
    {
        bug14_1 = byte3_5;
        BUG14 = bug14_1+bug14_2+bug14_3+bug14_4;
        emit sig_bug14(BUG14);
    }
    else if(byte3_5 == "0")
    {
        bug14_1 = byte3_5;
        BUG14 = bug14_1+bug14_2+bug14_3+bug14_4;
        emit sig_bug14(BUG14);
    }
    //输出短路
    if(byte3_7 == "1")
    {
        bug15_1 = byte3_7;
        BUG15 = bug15_1+bug15_2+bug15_3+bug15_4;
        emit sig_bug15(BUG15);
    }
    else if(byte3_7 == "0")
    {
        bug15_1 = byte3_7;
        BUG15 = bug15_1+bug15_2+bug15_3+bug15_4;
        emit sig_bug15(BUG15);
    }
    //BUG1 = bug1_+bug2_5+bug3_5+bug4_1+bug5_1+bug6_1+bug7_1+bug8_1+bug9_1+bug10_1+bug11_1+bug12_1+bug13_1+bug14_1+bug15_1;

    //开机状态
    if(byte1_1 =="1" || byte2_7 == "1")
    {
        ui->lightButton_start->setRed();
    }
    else if(byte1_1 =="0" || byte2_7 == "0")
    {
        ui->lightButton_start->setGreen();
    }
    else if(byte1_1 =="0" && byte2_7 == "0")
    {
        ui->lightButton_start->setGray();
    }

    //故障显示
    if(byte2_6 == "0")
    {
        ui->lightButton_fault->setGreen();
    }
    else if(byte2_6 == "1")
    {
        ui->lightButton_fault->setRed();
        emit sig_module1_bug(da1);
    }

    //限功率状态
    if(byte1_7 == "1")
    {
        ui->lightButton_W1->setGreen();
    }
    else if(byte1_7 == "0")
    {
        ui->lightButton_W1->setGray();
    }

    //walkin状态
    if(byte2_1 == "1")
    {
        ui->lightButton_Walkin->setGreen();
    }
    else if(byte2_1 == "0")
    {
        ui->lightButton_Walkin->setRed();
    }

    //休眠
    if(byte3_3 == "1")
    {
        ui->lightButton_sleep1->setGreen();
    }
    else if(byte3_3 == "0")
    {
        ui->lightButton_sleep1->setGray();
    }
}

void MainWindow::Module2_state(QString da1)
{
    QString byte0 = da1.mid(8,2);
    int tem = byte0.toInt(0,16);
    ui->lineEdit_module2_tem->setText(QString::number(tem)+"℃");
    QString byte1 = QString("%1").arg(da1.mid(10,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态2
    QString byte2 = QString("%1").arg(da1.mid(12,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态1
    QString byte3 = QString("%1").arg(da1.mid(14,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte1_0 = byte1.mid(0,1);//模块 PFC 侧处于关机状态
    QString byte1_1 = byte1.mid(1,1);//输入过压告警
    QString byte1_2 = byte1.mid(2,1);//输入欠压告警
    QString byte1_3 = byte1.mid(3,1);//三相输入不平衡告警
    QString byte1_4 = byte1.mid(4,1);//三相输入缺相告警
    QString byte1_5 = byte1.mid(5,1);//模块严重不均流
    QString byte1_6 = byte1.mid(6,1);//模块 ID 重复
    QString byte1_7 = byte1.mid(7,1);//模块处于限功率状态

    QString byte2_0 = byte2.mid(0,1);//模块通信中断告警
    QString byte2_1 = byte2.mid(1,1);//WALK-IN 使能
    QString byte2_2 = byte2.mid(2,1);//输出过压告警
    QString byte2_3 = byte2.mid(3,1);//过温告警
    QString byte2_4 = byte2.mid(4,1);//风扇故障告警
    QString byte2_5 = byte2.mid(5,1);//模块保护告警
    QString byte2_6 = byte2.mid(6,1);//模块故障告警
    QString byte2_7 = byte2.mid(7,1);//模块 DC 侧处于关机状态

    QString byte3_2 = byte3.mid(2,1);//模块放电异常
    QString byte3_3 = byte3.mid(3,1);//模块休眠
    QString byte3_4 = byte3.mid(4,1);//输入或母线异常
    QString byte3_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte3_7 = byte3.mid(7,1);//输出短路

    //输入过压告警
    if(byte1_1 == "1")
    {
        bug1_2 = byte1_1;
        BUG1 = bug1_1+bug1_2+bug1_3+bug1_4;
        emit sig_bug1(BUG1);
    }
    else if(byte1_1 == "0")
    {
        bug1_2 = byte1_1;
        BUG1 = bug1_1+bug1_2+bug1_3+bug1_4;
        emit sig_bug1(BUG1);
    }
    //输入欠压告警
    if(byte1_2 == "1")
    {
        bug2_2 = byte1_2;
        BUG2 = bug2_1+bug2_2+bug2_3+bug2_4;
        emit sig_bug2(BUG2);
    }
    else if(byte1_2 == "0")
    {
        bug2_2 = byte1_2;
        BUG2 = bug2_1+bug2_2+bug2_3+bug2_4;
        emit sig_bug2(BUG2);
    }
    //三相输入不平衡告警
    if(byte1_3 == "1")
    {
        bug3_2 = byte1_3;
        BUG3 = bug3_1+bug3_2+bug3_3+bug3_4;
        emit sig_bug3(BUG3);
    }
    else if(byte1_3 == "0")
    {
        bug3_2 = byte1_3;
        BUG3 = bug3_1+bug3_2+bug3_3+bug3_4;
        emit sig_bug3(BUG3);
    }
    //三相输入缺相告警
    if(byte1_4 == "1")
    {
        bug4_2 = byte1_4;
        BUG4 = bug4_1+bug4_2+bug4_3+bug4_4;
        emit sig_bug4(BUG4);
    }
    else if(byte1_4 == "0")
    {
        bug4_2 = byte1_4;
        BUG4 = bug4_1+bug4_2+bug4_3+bug4_4;
        emit sig_bug4(BUG4);
    }
    //模块严重不均流
    if(byte1_5 == "1")
    {
        bug5_2 = byte1_5;
        BUG5 = bug5_1+bug5_2+bug5_3+bug5_4;
        emit sig_bug5(BUG5);
    }
    else if(byte1_5 == "0")
    {
        bug5_2 = byte1_5;
        BUG5 = bug5_1+bug5_2+bug5_3+bug5_4;
        emit sig_bug5(BUG5);
    }
    //模块 ID 重复
    if(byte1_6 == "1")
    {
        bug6_2 = byte1_6;
        BUG6 = bug6_1+bug6_2+bug6_3+bug6_4;
        emit sig_bug6(BUG6);
    }
    else if(byte1_6 == "0")
    {
        bug6_2 = byte1_6;
        BUG6 = bug6_1+bug6_2+bug6_3+bug6_4;
        emit sig_bug6(BUG6);
    }
    //模块通信中断告警
    if(byte2_0 == "1")
    {
        bug7_2 = byte2_0;
        BUG7 = bug7_1+bug7_2+bug7_3+bug7_4;
        emit sig_bug7(BUG7);
    }
    else if(byte2_0 == "0")
    {
        bug7_2 = byte2_0;
        BUG7 = bug7_1+bug7_2+bug7_3+bug7_4;
        emit sig_bug7(BUG7);
    }
    //输出过压告警
    if(byte2_2 == "1")
    {
        bug8_2 = byte2_2;
        BUG8 = bug8_1+bug8_2+bug8_3+bug8_4;
        emit sig_bug8(BUG8);
    }
    else if(byte2_2 == "0")
    {
        bug8_2 = byte2_2;
        BUG8 = bug8_1+bug8_2+bug8_3+bug8_4;
        emit sig_bug8(BUG8);
    }
    //过温告警
    if(byte2_3 == "1")
    {
        bug9_2 = byte2_3;
        BUG9 = bug9_1+bug9_2+bug9_3+bug9_4;
        emit sig_bug9(BUG9);
    }
    else if(byte2_3 == "0")
    {
        bug9_2 = byte2_3;
        BUG9 = bug9_1+bug9_2+bug9_3+bug9_4;
        emit sig_bug9(BUG9);
    }
    //风扇故障告警
    if(byte2_4 == "1")
    {
        bug10_2 = byte2_4;
        BUG10 = bug10_1+bug10_2+bug10_3+bug10_4;
        emit sig_bug10(BUG10);
    }
    else if(byte2_4 == "0")
    {
        bug10_2 = byte2_4;
        BUG10 = bug10_1+bug10_2+bug10_3+bug10_4;
        emit sig_bug10(BUG10);
    }
    //模块保护告警
    if(byte2_5 == "1")
    {
        bug11_2 = byte2_5;
        BUG11 = bug11_1+bug11_2+bug11_3+bug11_4;
        emit sig_bug11(BUG11);
    }
    else if(byte2_5 == "0")
    {
        bug11_2 = byte2_5;
        BUG11 = bug11_1+bug11_2+bug11_3+bug11_4;
        emit sig_bug11(BUG11);
    }
    //模块放电异常
    if(byte3_2 == "1")
    {
        bug12_2 = byte3_2;
        BUG12 = bug12_1+bug12_2+bug12_3+bug12_4;
        emit sig_bug12(BUG12);
    }
    else if(byte3_2 == "0")
    {
        bug12_2 = byte3_2;
        BUG12 = bug12_1+bug12_2+bug12_3+bug12_4;
        emit sig_bug12(BUG12);
    }
    //输入或母线异常
    if(byte3_4 == "1")
    {
        bug13_2 = byte3_4;
        BUG13 = bug13_1+bug13_2+bug13_3+bug13_4;
        emit sig_bug13(BUG13);
    }
    else if(byte3_4 == "0")
    {
        bug13_2 = byte3_4;
        BUG13 = bug13_1+bug13_2+bug13_3+bug13_4;
        emit sig_bug13(BUG13);
    }
    //模块内部通信故障
    if(byte3_5 == "1")
    {
        bug14_2 = byte3_5;
        BUG14 = bug14_1+bug14_2+bug14_3+bug14_4;
        emit sig_bug14(BUG14);
    }
    else if(byte3_5 == "0")
    {
        bug14_2 = byte3_5;
        BUG14 = bug14_1+bug14_2+bug14_3+bug14_4;
        emit sig_bug14(BUG14);
    }
    //输出短路
    if(byte3_7 == "1")
    {
        bug15_2 = byte3_7;
        BUG15 = bug15_1+bug15_2+bug15_3+bug15_4;
        emit sig_bug15(BUG15);
    }
    else if(byte3_7 == "0")
    {
        bug15_2 = byte3_7;
        BUG15 = bug15_1+bug15_2+bug15_3+bug15_4;
        emit sig_bug15(BUG15);
    }

    //开机状态
    if(byte1_1 =="1" || byte2_7 == "1")
    {
        ui->lightButton_start_3->setRed();
    }
    else if(byte1_1 =="0" || byte2_7 == "0")
    {
        ui->lightButton_start_3->setGreen();
    }
    else if(byte1_1 =="0" && byte2_7 == "0")
    {
        ui->lightButton_start_3->setGray();
    }

    //故障显示
    if(byte2_6 == "0")
    {
        ui->lightButton_fault_2->setGreen();
    }
    else if(byte2_6 == "1")
    {
        ui->lightButton_fault_2->setRed();
        emit sig_module2_bug(da1);
    }

    //限功率状态
    if(byte1_7 == "1")
    {
        ui->lightButton_W2->setGreen();
    }
    else if(byte1_7 == "0")
    {
        ui->lightButton_W2->setGray();
    }

    //walkin状态
    if(byte2_1 == "1")
    {
        ui->lightButton_Walkin_2->setGreen();
    }
    else if(byte2_1 == "0")
    {
        ui->lightButton_Walkin_2->setRed();
    }

    //休眠
    if(byte3_3 == "1")
    {
        ui->lightButton_sleep2->setGreen();
    }
    else if(byte3_3 == "0")
    {
        ui->lightButton_sleep2->setGray();
    }
}

void MainWindow::Module3_state(QString da1)
{
    QString byte0 = da1.mid(8,2);
    int tem = byte0.toInt(0,16);
    ui->lineEdit_module3_tem->setText(QString::number(tem)+"℃");
    QString byte1 = QString("%1").arg(da1.mid(10,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态2
    QString byte2 = QString("%1").arg(da1.mid(12,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态1
    QString byte3 = QString("%1").arg(da1.mid(14,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte1_0 = byte1.mid(0,1);//模块 PFC 侧处于关机状态
    QString byte1_1 = byte1.mid(1,1);//输入过压告警
    QString byte1_2 = byte1.mid(2,1);//输入欠压告警
    QString byte1_3 = byte1.mid(3,1);//三相输入不平衡告警
    QString byte1_4 = byte1.mid(4,1);//三相输入缺相告警
    QString byte1_5 = byte1.mid(5,1);//模块严重不均流
    QString byte1_6 = byte1.mid(6,1);//模块 ID 重复
    QString byte1_7 = byte1.mid(7,1);//模块处于限功率状态

    QString byte2_0 = byte2.mid(0,1);//模块通信中断告警
    QString byte2_1 = byte2.mid(1,1);//WALK-IN 使能
    QString byte2_2 = byte2.mid(2,1);//输出过压告警
    QString byte2_3 = byte2.mid(3,1);//过温告警
    QString byte2_4 = byte2.mid(4,1);//风扇故障告警
    QString byte2_5 = byte2.mid(5,1);//模块保护告警
    QString byte2_6 = byte2.mid(6,1);//模块故障告警
    QString byte2_7 = byte2.mid(7,1);//模块 DC 侧处于关机状态

    QString byte3_2 = byte3.mid(2,1);//模块放电异常
    QString byte3_3 = byte3.mid(3,1);//模块休眠
    QString byte3_4 = byte3.mid(4,1);//输入或母线异常
    QString byte3_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte3_7 = byte3.mid(7,1);//输出短路

    QString bug = byte1_1+byte1_2+byte1_3+byte1_4+byte1_5+byte1_6+byte2_0+byte2_2+byte2_3+byte2_4+byte2_5+byte2_6+byte3_2+byte3_4+byte3_5+byte3_7;

    //输入过压告警
    if(byte1_1 == "1")
    {
        bug1_3 = byte1_1;
        BUG1 = bug1_1+bug1_2+bug1_3+bug1_4;
        emit sig_bug1(BUG1);
    }
    else if(byte1_1 == "0")
    {
        bug1_3 = byte1_1;
        BUG1 = bug1_1+bug1_2+bug1_3+bug1_4;
        emit sig_bug1(BUG1);
    }
    //输入欠压告警
    if(byte1_2 == "1")
    {
        bug2_3 = byte1_2;
        BUG2 = bug2_1+bug2_2+bug2_3+bug2_4;
        emit sig_bug2(BUG2);
    }
    else if(byte1_2 == "0")
    {
        bug2_3 = byte1_2;
        BUG2 = bug2_1+bug2_2+bug2_3+bug2_4;
        emit sig_bug2(BUG2);
    }
    //三相输入不平衡告警
    if(byte1_3 == "1")
    {
        bug3_3 = byte1_3;
        BUG3 = bug3_1+bug3_2+bug3_3+bug3_4;
        emit sig_bug3(BUG3);
    }
    else if(byte1_3 == "0")
    {
        bug3_3 = byte1_3;
        BUG3 = bug3_1+bug3_2+bug3_3+bug3_4;
        emit sig_bug3(BUG3);
    }
    //三相输入缺相告警
    if(byte1_4 == "1")
    {
        bug4_3 = byte1_4;
        BUG4 = bug4_1+bug4_2+bug4_3+bug4_4;
        emit sig_bug4(BUG4);
    }
    else if(byte1_4 == "0")
    {
        bug4_3 = byte1_4;
        BUG4 = bug4_1+bug4_2+bug4_3+bug4_4;
        emit sig_bug4(BUG4);
    }
    //模块严重不均流
    if(byte1_5 == "1")
    {
        bug5_3 = byte1_5;
        BUG5 = bug5_1+bug5_2+bug5_3+bug5_4;
        emit sig_bug5(BUG5);
    }
    else if(byte1_5 == "0")
    {
        bug5_3 = byte1_5;
        BUG5 = bug5_1+bug5_2+bug5_3+bug5_4;
        emit sig_bug5(BUG5);
    }
    //模块 ID 重复
    if(byte1_6 == "1")
    {
        bug6_3 = byte1_6;
        BUG6 = bug6_1+bug6_2+bug6_3+bug6_4;
        emit sig_bug6(BUG6);
    }
    else if(byte1_6 == "0")
    {
        bug6_3 = byte1_6;
        BUG6 = bug6_1+bug6_2+bug6_3+bug6_4;
        emit sig_bug6(BUG6);
    }
    //模块通信中断告警
    if(byte2_0 == "1")
    {
        bug7_3 = byte2_0;
        BUG7 = bug7_1+bug7_2+bug7_3+bug7_4;
        emit sig_bug7(BUG7);
    }
    else if(byte2_0 == "0")
    {
        bug7_3 = byte2_0;
        BUG7 = bug7_1+bug7_2+bug7_3+bug7_4;
        emit sig_bug7(BUG7);
    }
    //输出过压告警
    if(byte2_2 == "1")
    {
        bug8_3 = byte2_2;
        BUG8 = bug8_1+bug8_2+bug8_3+bug8_4;
        emit sig_bug8(BUG8);
    }
    else if(byte2_2 == "0")
    {
        bug8_3 = byte2_2;
        BUG8 = bug8_1+bug8_2+bug8_3+bug8_4;
        emit sig_bug8(BUG8);
    }
    //过温告警
    if(byte2_3 == "1")
    {
        bug9_3 = byte2_3;
        BUG9 = bug9_1+bug9_2+bug9_3+bug9_4;
        emit sig_bug9(BUG9);
    }
    else if(byte2_3 == "0")
    {
        bug9_3 = byte2_3;
        BUG9 = bug9_1+bug9_2+bug9_3+bug9_4;
        emit sig_bug9(BUG9);
    }
    //风扇故障告警
    if(byte2_4 == "1")
    {
        bug10_3 = byte2_4;
        BUG10 = bug10_1+bug10_2+bug10_3+bug10_4;
        emit sig_bug10(BUG10);
    }
    else if(byte2_4 == "0")
    {
        bug10_3 = byte2_4;
        BUG10 = bug10_1+bug10_2+bug10_3+bug10_4;
        emit sig_bug10(BUG10);
    }
    //模块保护告警
    if(byte2_5 == "1")
    {
        bug11_3 = byte2_5;
        BUG11 = bug11_1+bug11_2+bug11_3+bug11_4;
        emit sig_bug11(BUG11);
    }
    else if(byte2_5 == "0")
    {
        bug11_3 = byte2_5;
        BUG11 = bug11_1+bug11_2+bug11_3+bug11_4;
        emit sig_bug11(BUG11);
    }
    //模块放电异常
    if(byte3_2 == "1")
    {
        bug12_3 = byte3_2;
        BUG12 = bug12_1+bug12_2+bug12_3+bug12_4;
        emit sig_bug12(BUG12);
    }
    else if(byte3_2 == "0")
    {
        bug12_3 = byte3_2;
        BUG12 = bug12_1+bug12_2+bug12_3+bug12_4;
        emit sig_bug12(BUG12);
    }
    //输入或母线异常
    if(byte3_4 == "1")
    {
        bug13_3 = byte3_4;
        BUG13 = bug13_1+bug13_2+bug13_3+bug13_4;
        emit sig_bug13(BUG13);
    }
    else if(byte3_4 == "0")
    {
        bug13_3 = byte3_4;
        BUG13 = bug13_1+bug13_2+bug13_3+bug13_4;
        emit sig_bug13(BUG13);
    }
    //模块内部通信故障
    if(byte3_5 == "1")
    {
        bug14_3 = byte3_5;
        BUG14 = bug14_1+bug14_2+bug14_3+bug14_4;
        emit sig_bug14(BUG14);
    }
    else if(byte3_5 == "0")
    {
        bug14_3 = byte3_5;
        BUG14 = bug14_1+bug14_2+bug14_3+bug14_4;
        emit sig_bug14(BUG14);
    }
    //输出短路
    if(byte3_7 == "1")
    {
        bug15_3 = byte3_7;
        BUG15 = bug15_1+bug15_2+bug15_3+bug15_4;
        emit sig_bug15(BUG15);
    }
    else if(byte3_7 == "0")
    {
        bug15_3 = byte3_7;
        BUG15 = bug15_1+bug15_2+bug15_3+bug15_4;
        emit sig_bug15(BUG15);
    }

    //开机状态
    if(byte1_1 =="1" || byte2_7 == "1")
    {
        ui->lightButton_start_4->setRed();
    }
    else if(byte1_1 =="0" || byte2_7 == "0")
    {
        ui->lightButton_start_4->setGreen();
    }
    else if(byte1_1 =="0" && byte2_7 == "0")
    {
        ui->lightButton_start_4->setGray();
    }

    //故障状态
    if(byte2_6 == "0")
    {
        ui->lightButton_fault_3->setGreen();
    }
    else if(byte2_6 == "1")
    {
        ui->lightButton_fault_3->setRed();
        emit sig_module3_bug(da1);
    }

    //功率状态
    if(byte1_7 == "1")
    {
        ui->lightButton_W3->setGreen();
    }
    else if(byte1_7 == "0")
    {
        ui->lightButton_W3->setGray();
    }

    //walkin状态
    if(byte2_1 == "1")
    {
        ui->lightButton_Walkin_3->setGreen();
    }
    else if(byte2_1 == "0")
    {
        ui->lightButton_Walkin_3->setRed();
    }

    //休眠
    if(byte3_3 == "1")
    {
        ui->lightButton_sleep3->setGreen();
    }
    else if(byte3_3 == "0")
    {
        ui->lightButton_sleep3->setGray();
    }
}

void MainWindow::Module4_state(QString da1)
{
    QString byte0 = da1.mid(8,2);
    int tem = byte0.toInt(0,16);
    ui->lineEdit_module4_tem->setText(QString::number(tem)+"℃");
    QString byte1 = QString("%1").arg(da1.mid(10,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态2
    QString byte2 = QString("%1").arg(da1.mid(12,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态1
    QString byte3 = QString("%1").arg(da1.mid(14,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte1_0 = byte1.mid(0,1);//模块 PFC 侧处于关机状态
    QString byte1_1 = byte1.mid(1,1);//输入过压告警
    QString byte1_2 = byte1.mid(2,1);//输入欠压告警
    QString byte1_3 = byte1.mid(3,1);//三相输入不平衡告警
    QString byte1_4 = byte1.mid(4,1);//三相输入缺相告警
    QString byte1_5 = byte1.mid(5,1);//模块严重不均流
    QString byte1_6 = byte1.mid(6,1);//模块 ID 重复
    QString byte1_7 = byte1.mid(7,1);//模块处于限功率状态

    QString byte2_0 = byte2.mid(0,1);//模块通信中断告警
    QString byte2_1 = byte2.mid(1,1);//WALK-IN 使能
    QString byte2_2 = byte2.mid(2,1);//输出过压告警
    QString byte2_3 = byte2.mid(3,1);//过温告警
    QString byte2_4 = byte2.mid(4,1);//风扇故障告警
    QString byte2_5 = byte2.mid(5,1);//模块保护告警
    QString byte2_6 = byte2.mid(6,1);//模块故障告警
    QString byte2_7 = byte2.mid(7,1);//模块 DC 侧处于关机状态

    QString byte3_2 = byte3.mid(2,1);//模块放电异常
    QString byte3_3 = byte3.mid(3,1);//模块休眠
    QString byte3_4 = byte3.mid(4,1);//输入或母线异常
    QString byte3_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte3_7 = byte3.mid(7,1);//输出短路

    QString bug = byte1_1+byte1_2+byte1_3+byte1_4+byte1_5+byte1_6+byte2_0+byte2_2+byte2_3+byte2_4+byte2_5+byte2_6+byte3_2+byte3_4+byte3_5+byte3_7;

    //输入过压告警
    if(byte1_1 == "1")
    {
        bug1_4 = byte1_1;
        BUG1 = bug1_1+bug1_2+bug1_3+bug1_4;
        emit sig_bug1(BUG1);
    }
    else if(byte1_1 == "0")
    {
        bug1_4 = byte1_1;
        BUG1 = bug1_1+bug1_2+bug1_3+bug1_4;
        emit sig_bug1(BUG1);
    }
    //输入欠压告警
    if(byte1_2 == "1")
    {
        bug2_4 = byte1_2;
        BUG2 = bug2_1+bug2_2+bug2_3+bug2_4;
        emit sig_bug2(BUG2);
    }
    else if(byte1_2 == "0")
    {
        bug2_4 = byte1_2;
        BUG2 = bug2_1+bug2_2+bug2_3+bug2_4;
        emit sig_bug2(BUG2);
    }
    //三相输入不平衡告警
    if(byte1_3 == "1")
    {
        bug3_4 = byte1_3;
        BUG3 = bug3_1+bug3_2+bug3_3+bug3_4;
        emit sig_bug3(BUG3);
    }
    else if(byte1_3 == "0")
    {
        bug3_4 = byte1_3;
        BUG3 = bug3_1+bug3_2+bug3_3+bug3_4;
        emit sig_bug3(BUG3);
    }
    //三相输入缺相告警
    if(byte1_4 == "1")
    {
        bug4_4 = byte1_4;
        BUG4 = bug4_1+bug4_2+bug4_3+bug4_4;
        emit sig_bug4(BUG4);
    }
    else if(byte1_4 == "0")
    {
        bug4_4 = byte1_4;
        BUG4 = bug4_1+bug4_2+bug4_3+bug4_4;
        emit sig_bug4(BUG4);
    }
    //模块严重不均流
    if(byte1_5 == "1")
    {
        bug5_4 = byte1_5;
        BUG5 = bug5_1+bug5_2+bug5_3+bug5_4;
        emit sig_bug5(BUG5);
    }
    else if(byte1_5 == "0")
    {
        bug5_4 = byte1_5;
        BUG5 = bug5_1+bug5_2+bug5_3+bug5_4;
        emit sig_bug5(BUG5);
    }
    //模块 ID 重复
    if(byte1_6 == "1")
    {
        bug6_4 = byte1_6;
        BUG6 = bug6_1+bug6_2+bug6_3+bug6_4;
        emit sig_bug6(BUG6);
    }
    else if(byte1_6 == "0")
    {
        bug6_4 = byte1_6;
        BUG6 = bug6_1+bug6_2+bug6_3+bug6_4;
        emit sig_bug6(BUG6);
    }
    //模块通信中断告警
    if(byte2_0 == "1")
    {
        bug7_4 = byte2_0;
        BUG7 = bug7_1+bug7_2+bug7_3+bug7_4;
        emit sig_bug7(BUG7);
    }
    else if(byte2_0 == "0")
    {
        bug7_4 = byte2_0;
        BUG7 = bug7_1+bug7_2+bug7_3+bug7_4;
        emit sig_bug7(BUG7);
    }
    //输出过压告警
    if(byte2_2 == "1")
    {
        bug8_4 = byte2_2;
        BUG8 = bug8_1+bug8_2+bug8_3+bug8_4;
        emit sig_bug8(BUG8);
    }
    else if(byte2_2 == "0")
    {
        bug8_4 = byte2_2;
        BUG8 = bug8_1+bug8_2+bug8_3+bug8_4;
        emit sig_bug8(BUG8);
    }
    //过温告警
    if(byte2_3 == "1")
    {
        bug9_4 = byte2_3;
        BUG9 = bug9_1+bug9_2+bug9_3+bug9_4;
        emit sig_bug9(BUG9);
    }
    else if(byte2_3 == "0")
    {
        bug9_4 = byte2_3;
        BUG9 = bug9_1+bug9_2+bug9_3+bug9_4;
        emit sig_bug9(BUG9);
    }
    //风扇故障告警
    if(byte2_4 == "1")
    {
        bug10_4 = byte2_4;
        BUG10 = bug10_1+bug10_2+bug10_3+bug10_4;
        emit sig_bug10(BUG10);
    }
    else if(byte2_4 == "0")
    {
        bug10_4 = byte2_4;
        BUG10 = bug10_1+bug10_2+bug10_3+bug10_4;
        emit sig_bug10(BUG10);
    }
    //模块保护告警
    if(byte2_5 == "1")
    {
        bug11_4 = byte2_5;
        BUG11 = bug11_1+bug11_2+bug11_3+bug11_4;
        emit sig_bug11(BUG11);
    }
    else if(byte2_5 == "0")
    {
        bug11_4 = byte2_5;
        BUG11 = bug11_1+bug11_2+bug11_3+bug11_4;
        emit sig_bug11(BUG11);
    }
    //模块放电异常
    if(byte3_2 == "1")
    {
        bug12_4 = byte3_2;
        BUG12 = bug12_1+bug12_2+bug12_3+bug12_4;
        emit sig_bug12(BUG12);
    }
    else if(byte3_2 == "0")
    {
        bug12_4 = byte3_2;
        BUG12 = bug12_1+bug12_2+bug12_3+bug12_4;
        emit sig_bug12(BUG12);
    }
    //输入或母线异常
    if(byte3_4 == "1")
    {
        bug13_4 = byte3_4;
        BUG13 = bug13_1+bug13_2+bug13_3+bug13_4;
        emit sig_bug13(BUG13);
    }
    else if(byte3_4 == "0")
    {
        bug13_4 = byte3_4;
        BUG13 = bug13_1+bug13_2+bug13_3+bug13_4;
        emit sig_bug13(BUG13);
    }
    //模块内部通信故障
    if(byte3_5 == "1")
    {
        bug14_4 = byte3_5;
        BUG14 = bug14_1+bug14_2+bug14_3+bug14_4;
        emit sig_bug14(BUG14);
    }
    else if(byte3_5 == "0")
    {
        bug14_4 = byte3_5;
        BUG14 = bug14_1+bug14_2+bug14_3+bug14_4;
        emit sig_bug14(BUG14);
    }
    //输出短路
    if(byte3_7 == "1")
    {
        bug15_4 = byte3_7;
        BUG15 = bug15_1+bug15_2+bug15_3+bug15_4;
        emit sig_bug15(BUG15);
    }
    else if(byte3_7 == "0")
    {
        bug15_4 = byte3_7;
        BUG15 = bug15_1+bug15_2+bug15_3+bug15_4;
        emit sig_bug15(BUG15);
    }

    //开机状态
    if(byte1_1 =="1" || byte2_7 == "1")
    {
        ui->lightButton_start_5->setRed();
    }
    else if(byte1_1 =="0" || byte2_7 == "0")
    {
        ui->lightButton_start_5->setGreen();
    }
    else if(byte1_1 =="0" && byte2_7 == "0")
    {
        ui->lightButton_start_5->setGray();
    }

    //故障状态
    if(byte2_6 == "0")
    {
        ui->lightButton_fault_4->setGreen();
    }
    else if(byte2_6 == "1")
    {
        ui->lightButton_fault_4->setRed();
        emit sig_module4_bug(da1);
    }

    //功率状态
    if(byte1_7 == "1")
    {
        ui->lightButton_W4->setGreen();
    }
    else if(byte1_7 == "0")
    {
        ui->lightButton_W4->setGray();
    }

    //walkin状态
    if(byte2_1 == "1")
    {
        ui->lightButton_Walkin_4->setGreen();
    }
    else if(byte2_1 == "0")
    {
        ui->lightButton_Walkin_4->setRed();
    }

    //休眠
    if(byte3_3 == "1")
    {
        ui->lightButton_sleep4->setGreen();
    }
    else if(byte3_3 == "0")
    {
        ui->lightButton_sleep4->setGray();
    }
}

void MainWindow::CEG1_View(QString da1)
{
    QString data1 = da1.mid(14,2);
    if(data1 == "A1")
    {
        ui->lineEdit_CEG1->setText("MPPT模式");
    }
    else if(data1 == "A2")
    {
        ui->lineEdit_CEG1->setText("输入恒压模式");
    }
}

void MainWindow::CEG2_View(QString da1)
{
    QString data1 = da1.mid(14,2);
    if(data1 == "A1")
    {
        ui->lineEdit_CEG2->setText("MPPT模式");
    }
    else if(data1 == "A2")
    {
        ui->lineEdit_CEG2->setText("输入恒压模式");
    }
}

void MainWindow::CEG3_View(QString da1)
{
    QString data1 = da1.mid(14,2);
    if(data1 == "A1")
    {
        ui->lineEdit_CEG3->setText("MPPT模式");
    }
    else if(data1 == "A2")
    {
        ui->lineEdit_CEG3->setText("输入恒压模式");
    }
}

void MainWindow::CEG4_View(QString da1)
{
    QString data1 = da1.mid(14,2);
    if(data1 == "A1")
    {
        ui->lineEdit_CEG4->setText("MPPT模式");
    }
    else if(data1 == "A2")
    {
        ui->lineEdit_CEG4->setText("输入恒压模式");
    }
}

void MainWindow::customPlotModule_V_A()
{
    plot = ui->rechargePlot_VA;

    //渐变背景颜色
    QLinearGradient gradient(0, 0, 0, 400);
    gradient.setColorAt(0, QColor(90, 90, 90));
    gradient.setColorAt(0.38, QColor(105, 105, 105));
    gradient.setColorAt(1, QColor(70, 70, 70));
    plot->setBackground(QBrush(gradient));

    //添加图的title
    QCPTextElement *title_txt = new QCPTextElement(plot,"模块电压/电流曲线", QFont("sans", 12, QFont::Bold));
    title_txt->setTextColor(Qt::white);  //修改颜色
    plot->plotLayout()->insertRow(0);
    plot->plotLayout()->addElement(0, 0, title_txt);

    //日期做X轴
    QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
    dateTicker->setDateTimeFormat("hh:mm:ss"); //日期格式
    plot->xAxis->setTicker(dateTicker); //设置X轴为时间轴

    connect(plot->xAxis, SIGNAL(rangeChanged(QCPRange)), plot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->rechargePlot_VA, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
    //connect(plot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));

    plot->setInteractions(QCP::iRangeDrag
                          |QCP::iRangeZoom
                          /*|QCP::iSelectLegend
                          |QCP::iSelectAxes
                          |QCP::iSelectPlottables*/);
    QList<QCPAxis*> h_axes, v_axes;
    h_axes << plot->xAxis << plot->xAxis; ///左右y轴共用同一个x轴
    v_axes << plot->yAxis <<plot->yAxis2;
    plot->axisRect()->setRangeZoomAxes(h_axes, v_axes);
    plot->axisRect()->setRangeDragAxes(h_axes, v_axes);
    //plot->axisRect()->setRangeZoomFactor(1.2,1);//x方向为1.2 y为1 是不改变。

    //坐标轴设置
    QFont font;
    font.setPixelSize(18);
    plot->xAxis->setLabel("时间【时:分:秒】");
    plot->xAxis->setTickLabels(true); //显示刻度标签
    //plot->xAxis->setLabelFont(font);
    plot->yAxis->setRange(0, 1000);
    plot->yAxis->setLabel("电压(V)");
    plot->yAxis->setLabelFont(font);
    plot->yAxis2->setLabel("电流(A)");
    plot->yAxis2->setLabelFont(font);
    plot->yAxis2->setVisible(true);
    plot->yAxis2->setRange(0, 200);  //当前Y_2轴显示的范围

    plot->xAxis->setBasePen(QPen(Qt::white,1));//设置x轴坐标轴颜色
    plot->yAxis->setBasePen(QPen(Qt::white,1));//设置y轴坐标轴颜色
    plot->yAxis2->setBasePen(QPen(Qt::white,1));//设置y轴坐标轴颜色
    plot->xAxis->setTickPen(QPen(Qt::white, 1));  // 轴刻度线的画笔
    plot->yAxis->setTickPen(QPen(Qt::white, 1));  // 轴刻度线的画笔
    plot->yAxis2->setTickPen(QPen(Qt::white, 1));  // 轴刻度线的画笔
    plot->xAxis->setSubTickPen(QPen(Qt::white, 1)); // 轴子刻度线的画笔
    plot->yAxis->setSubTickPen(QPen(Qt::white, 1)); // 轴子刻度线的画笔
    plot->yAxis2->setSubTickPen(QPen(Qt::white, 1)); // 轴子刻度线的画笔
    plot->xAxis->setTickLabelColor(Qt::white);//设置x轴坐标颜色
    plot->yAxis->setTickLabelColor(Qt::white);//设置y轴坐标颜色
    plot->yAxis2->setTickLabelColor(Qt::white);//设置y轴坐标颜色
    plot->xAxis->setLabelColor(Qt::white);//设置x轴名称颜色
    plot->yAxis->setLabelColor(Qt::white);//设置y轴名称颜色
    plot->yAxis2->setLabelColor(Qt::white);//设置y轴名称颜色

    //设置图例属性
    plot->xAxis->grid()->setPen(QPen(QColor(180, 180, 180), 1, Qt::PenStyle::DashLine));//网格白色虚线
    plot->yAxis->grid()->setPen(QPen(QColor(180, 180, 180), 1, Qt::PenStyle::DashLine));//网格白色虚线
    plot->xAxis->grid()->setSubGridPen(QPen(QColor(50, 50, 50), 1, Qt::DotLine));//网格浅色点线
    plot->yAxis->grid()->setSubGridPen(QPen(QColor(50, 50, 50), 1, Qt::DotLine));//网格浅色点线
    //plot->xAxis->grid()->setSubGridVisible(true);//显示x轴子网格线
    //plot->yAxis->grid()->setSubGridVisible(true);//显示要轴子网格线
    plot->xAxis->grid()->setZeroLinePen(QPen(Qt::white));//x轴0线颜色白色
    plot->yAxis->grid()->setZeroLinePen(QPen(Qt::white));//y轴0线颜色白色


    //电压曲线
    plot->addGraph(plot->xAxis,plot->yAxis);                              //向绘图区域QCustomPlot添加一条曲线
    plot->addGraph(plot->xAxis,plot->yAxis);
    plot->addGraph(plot->xAxis,plot->yAxis);                              //向绘图区域QCustomPlot添加一条曲线
    plot->addGraph(plot->xAxis,plot->yAxis);

    //电流曲线
    plot->addGraph(plot->xAxis,plot->yAxis2);                              //向绘图区域QCustomPlot添加一条曲线
    plot->addGraph(plot->xAxis,plot->yAxis2);
    plot->addGraph(plot->xAxis,plot->yAxis2);                              //向绘图区域QCustomPlot添加一条曲线
    plot->addGraph(plot->xAxis,plot->yAxis2);

//    //曲线颜色
//    plot->graph(0)->setPen(QPen(QColor("#0066FF")));                //绘制曲线0的画刷颜色为红色
//    plot->graph(1)->setPen(QPen(QColor("#6A5ACD")));              //绘制曲线1的画刷颜色为蓝色
//    plot->graph(2)->setPen(QPen(QColor("#00FFFF")));                //绘制曲线0的画刷颜色为红色
//    plot->graph(3)->setPen(QPen(QColor("#CC00FF")));

//    plot->graph(4)->setPen(QPen(QColor("#2E8B57")));
//    plot->graph(5)->setPen(QPen(QColor("#77FF00")));
//    plot->graph(6)->setPen(QPen(QColor("#00C78C")));
//    plot->graph(7)->setPen(QPen(QColor("#BDFCC9")));

    QPen pen;
    pen.setWidth(3);//设置线宽
    pen.setColor(Qt::blue);
    QPen pen1;
    pen1.setWidth(3);//设置线宽
    pen1.setColor(Qt::cyan);
    QPen pen2;
    pen2.setWidth(3);//设置线宽
    pen2.setColor(Qt::magenta);
    QPen pen3;
    pen3.setWidth(3);//设置线宽
    pen3.setColor(Qt::darkBlue);
    QPen pen4;
    pen4.setWidth(3);//设置线宽
    pen4.setColor(Qt::green);
    QPen pen5;
    pen5.setWidth(3);//设置线宽
    pen5.setColor(Qt::yellow);
    QPen pen6;
    pen6.setWidth(3);//设置线宽
    pen6.setColor(Qt::darkGreen);
    QPen pen7;
    pen7.setWidth(3);//设置线宽
    pen7.setColor(Qt::darkYellow);
    plot->graph(0)->setPen(pen);
    plot->graph(1)->setPen(pen1);
    plot->graph(2)->setPen(pen2);
    plot->graph(3)->setPen(pen3);
    plot->graph(4)->setPen(pen4);
    plot->graph(5)->setPen(pen5);
    plot->graph(6)->setPen(pen6);
    plot->graph(7)->setPen(pen7);

    //图例显示
    plot->legend->setVisible(true);
    plot->graph(0)->setName("电压1");
    plot->graph(1)->setName("电压2");
    plot->graph(2)->setName("电压3");
    plot->graph(3)->setName("电压4");

    plot->graph(4)->setName("电流1");
    plot->graph(5)->setName("电流2");
    plot->graph(6)->setName("电流3");
    plot->graph(7)->setName("电流4");

    //图例选中图像信号槽连接

//    ui->plot->setInteractions(QCP::iSelectLegend | QCP::iSelectPlottables);
//    ui->plot->legend->setSelectableParts(QCPLegend::spItems);


    //图像自适应坐标轴
    plot->graph(0)->rescaleAxes();
    plot->graph(1)->rescaleAxes();
    plot->graph(2)->rescaleAxes();
    plot->graph(3)->rescaleAxes();
    plot->graph(4)->rescaleAxes();
    plot->graph(5)->rescaleAxes();
    plot->graph(6)->rescaleAxes();
    plot->graph(7)->rescaleAxes();

    plot->legend->setBrush(QBrush(Qt::transparent));     //设置图例透明无边框
    //plot_2->legend->setBorderPen(Qt::NoPen);//图例边框隐藏
    //plot_2->legend->setFont(QFont("sans", 16, QFont::Bold));
    plot->legend->setBorderPen(Qt::NoPen);
    plot->legend->setVisible(true);//设置曲线名称可见
    plot->legend->setTextColor(Qt::white);//black

    //游标初始化定义
    tracer = new QCPItemTracer(plot);
    //tracer->setInterpolating(false);
    tracer->setStyle(QCPItemTracer::tsCircle);
    tracer->setPen(QPen(Qt::red));
    tracer->setBrush(Qt::red);
    tracer->setSize(6);

    connect(plot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoveEvent(QMouseEvent*)));
    //connect(plot, SIGNAL(legendDoubleClick(QCPLegend*, QCPAbstractLegendItem*, QMouseEvent*)), this, SLOT(when_legendDoubleClick(QCPLegend*, QCPAbstractLegendItem*, QMouseEvent*)));

    //框选放大功能
//    plot->selectionRect()->setPen(QPen(Qt::black,1,Qt::DashLine));//设置选框的样式：虚线
//    plot->selectionRect()->setBrush(QBrush(QColor(0,0,100,50)));//设置选框的样式：半透明浅蓝
//    plot->setSelectionRectMode(QCP::SelectionRectMode::srmZoom);

    //设置鼠标放于绘图区，变为手型
    plot->setCursor(QCursor(Qt::PointingHandCursor));
}

void MainWindow::System_set(QString id1, QString da1)
{
    QString dataV = da1.mid(0,8);//电压
    QString dataA = da1.mid(8,8);//电流值
    int vol  = dataV.toInt(0,16)/1000;
    int cur  = dataV.toInt(0,16)/1000;
    ui->cc1state_le_4->setText(QString::number(vol));
    ui->cc1state_le_5->setText(QString::number(cur));
//    if(id1 == "02DCF001")
//    {
//        if(da1 == Data_set)
//        {
//            set1 = 1;
//        }
//        else if(da1 != Data_set)
//        {
//            set1 = 0;
//        }
//    }
//    if(id1 == "02DCF002")
//    {
//        if(da1 == Data_set)
//        {
//            set2 = 1;
//        }
//        else if(da1 != Data_set)
//        {
//            set2 = 0;
//        }
//    }
//    if(id1 == "02DCF003")
//    {
//        if(da1 == Data_set)
//        {
//            set3 = 1;
//        }
//        else if(da1 != Data_set)
//        {
//            set3 = 0;
//        }
//    }
//    if(id1 == "02DCF004")
//    {
//        if(da1 == Data_set)
//        {
//            set4 = 1;
//        }
//        else if(da1 != Data_set)
//        {
//            set4 = 0;
//        }
//    }
//    sys_set = set1+set2+set3+set4;
//    if(sys_set == sys_num)
//    {
//        QMessageBox::information(nullptr,"提示","设置成功");
//    }
//    else if(sys_set != sys_num)
//    {
//        QMessageBox::information(nullptr,"提示","设置失败");
//    }
}

void MainWindow::Module_set_Series(QString da1)
{
    //QString data = "00030D40";
    QString dataV = da1.mid(0,8);//电压
    QString dataA = da1.mid(8,8);//电流值
    int vol  = dataV.toInt(0,16)/1000;
    int cur  = dataA.toInt(0,16)/1000;
    ui->cc1state_le_4->setText(QString::number(vol));
    ui->cc1state_le_5->setText(QString::number(cur));
    //qDebug()<<vol;
//    if(da1 == Data_set)
//    {
//        QMessageBox::information(nullptr,"提示","设置成功");
//    }
//    else if(da1 != Data_set)
//    {
//        QMessageBox::information(nullptr,"提示","设置失败");
//    }
}

void MainWindow::Module1_set(QString da1)
{
//    if(da1.toUpper() != NULL)
//    {
        QMessageBox::information(nullptr,"提示","设置成功");
//    }
//    else if(da1.toUpper() != Data_set)
//    {
//        QMessageBox::information(nullptr,"提示","设置失败");
//    }
}


void MainWindow::Module2_set(QString da1)
{
//    if(da1 == Data_set)
//    {
        QMessageBox::information(nullptr,"提示","设置成功");
//    }
//    else if(da1 != Data_set)
//    {
//        QMessageBox::information(nullptr,"提示","设置失败");
//    }
}

void MainWindow::Module3_set(QString da1)
{
//    if(da1 == Data_set)
//    {
        QMessageBox::information(nullptr,"提示","设置成功");
//    }
//    else if(da1 != Data_set)
//    {
//        QMessageBox::information(nullptr,"提示","设置失败");
//    }
}

void MainWindow::Module4_set(QString da1)
{
//    if(da1 == Data_set)
//    {
        QMessageBox::information(nullptr,"提示","设置成功");
//    }
//    else if(da1 != Data_set)
//    {
//        QMessageBox::information(nullptr,"提示","设置失败");
//    }
}

void MainWindow::module1_walkin(QString id, QString da1)
{
//    if(id == "02D3F001")
//    {
//        if(da1 == "0000000000000000")
//        {
//            wals1 = 0;
//        }
//        else if(da1 == "0100000000000000")
//        {
//            wals1 = 1;
//        }
//    }
//    if(id == "02D3F002")
//    {
//        if(da1 == "0000000000000000")
//        {
//            wals2 = 0;
//        }
//        else if(da1 == "0100000000000000")
//        {
//            wals2 = 1;
//        }
//    }
//    if(id == "02D3F003")
//    {
//        if(da1 == "0000000000000000")
//        {
//            wals3 = 0;
//        }
//        else if(da1 == "0100000000000000")
//        {
//            wals3 = 1;
//        }
//    }
//    if(id == "02D3F004")
//    {
//        if(da1 == "0000000000000000")
//        {
//            wals4 = 0;
//        }
//        else if(da1 == "0100000000000000")
//        {
//            wals4 = 1;
//        }
//    }

//    Wals = wals1+wals2+wals3+wals4;
//    if(Wals != 0)
//    {
//        ui->lightButton_Walkin->setGreen();
//        ui->btnWalkin_start->setDisabled(true);
//    }
//    else if(Wals == 0)
//    {
//        ui->lightButton_Walkin->setRed();
//        ui->btnWalkin_start->setDisabled(false);
//    }
}

void MainWindow::module2_walkin(QString da1)
{
//    if(da1 == "0000000000000000")
//    {
//        wals2 = 0;
//    }
//    else if(da1 == "0100000000000000")
//    {
//        wals2 = 1;
//    }
//    Wals = wals1+wals2+wals3+wals4;
//    if(Wals != 0)
//    {
//        ui->lightButton_Walkin->setGreen();
//        ui->btnWalkin_start->setDisabled(true);
//    }
//    else if(Wals == 0)
//    {
//        ui->lightButton_Walkin->setRed();
//        ui->btnWalkin_start->setDisabled(false);
//    }
}

void MainWindow::module3_walkin(QString da1)
{
//    if(da1 == "0000000000000000")
//    {
//        wals3 = 0;
//    }
//    else if(da1 == "0100000000000000")
//    {
//        wals3 = 1;
//    }
//    Wals = wals1+wals2+wals3+wals4;
//    if(Wals != 0)
//    {
//        ui->lightButton_Walkin->setGreen();
//        ui->btnWalkin_start->setDisabled(true);
//    }
//    else if(Wals == 0)
//    {
//        ui->lightButton_Walkin->setRed();
//        ui->btnWalkin_start->setDisabled(false);
//    }
}

void MainWindow::module4_walkin(QString da1)
{
//    if(da1 == "0000000000000000")
//    {
//        wals4 = 0;
//    }
//    else if(da1 == "0100000000000000")
//    {
//        wals4 = 1;
//    }
//    Wals = wals1+wals2+wals3+wals4;
//    if(Wals != 0)
//    {
//        ui->lightButton_Walkin->setGreen();
//        ui->btnWalkin_start->setDisabled(true);
//    }
//    else if(Wals == 0)
//    {
//        ui->lightButton_Walkin->setRed();
//        ui->btnWalkin_start->setDisabled(false);
//    }
}

void MainWindow::module1_start(QString da1)
{
    if(da1 == "0000000000000000")
    {
        ui->lightButton_start->setGreen();
    }
    else if(da1 == "0100000000000000")
    {
        ui->lightButton_start->setRed();
    }

}

void MainWindow::module2_start(QString da1)
{
    if(da1 == "0000000000000000")
    {
        ui->lightButton_start_3->setGreen();
    }
    else if(da1 == "0100000000000000")
    {
        ui->lightButton_start_3->setRed();
    }
}

void MainWindow::module3_start(QString da1)
{
    if(da1 == "0000000000000000")
    {
        ui->lightButton_start_4->setGreen();
    }
    else if(da1 == "0100000000000000")
    {
        ui->lightButton_start_4->setRed();
    }
}

void MainWindow::module4_start(QString da1)
{
    if(da1 == "0000000000000000")
    {
        ui->lightButton_start_5->setGreen();
    }
    else if(da1 == "0100000000000000")
    {
        ui->lightButton_start_5->setRed();
    }
}

//输入过压告警
void MainWindow::Bug1(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_in_guoya->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_in_guoya->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//输入欠压告警
void MainWindow::Bug2(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_in_qianya->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_in_qianya->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//三相输入不平衡告警
void MainWindow::Bug3(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_sanxiang_bupingheng->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_sanxiang_bupingheng->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//三相输入缺相告警
void MainWindow::Bug4(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_sanxaing_quexiang->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_sanxaing_quexiang->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//模块严重不均流
void MainWindow::Bug5(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_junliu->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_junliu->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//模块 ID 重复
void MainWindow::Bug6(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_ID->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_ID->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//模块通信中断告警
void MainWindow::Bug7(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_tongxin->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_tongxin->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//输出过压告警
void MainWindow::Bug8(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_out_guoya->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_out_guoya->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//过温告警
void MainWindow::Bug9(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_guowen->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_guowen->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//风扇故障告警
void MainWindow::Bug10(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_fengshan->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_fengshan->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//模块保护告警
void MainWindow::Bug11(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_mokuai->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_mokuai->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//模块放电异常
void MainWindow::Bug12(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_fangdian->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_fangdian->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//输入或母线异常
void MainWindow::Bug13(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_in_muxian->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_in_muxian->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//模块内部通信故障
void MainWindow::Bug14(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_tongxin_fault->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_tongxin_fault->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}
//输出短路
void MainWindow::Bug15(QString a1)
{
    if(a1 == "0000")
    {
        ui->lightButton_out_duanlu->setGreen();
    }
    else if(a1 != "0000")
    {
        ui->lightButton_out_duanlu->setRed();
    }
    BUG_all = BUG1+BUG2+BUG3+BUG4+BUG5+BUG6+BUG7+BUG8+BUG9+BUG10+BUG11+BUG12+BUG13+BUG14+BUG15;
    emit sig_bugAll(BUG_all);
}

void MainWindow::Bug_All(QString a1)
{
    if(a1 != "000000000000000000000000000000000000000000000000000000000000")
    {
        int ID;
        ID = 0x02DA01F0;
        QString Data = "0100000000000000";
        std::vector<int> vec;
        QByteArray data1 = Data.toUpper().toLatin1();
        for(int i=0; i<8; i++)
        {
            vec.push_back(Data.mid(2*i,2).toInt(0,16));
            double vec = QRandomGenerator::global()->generateDouble();
        }
        emit SIGtocansen(ID,vec);
    }
}

void MainWindow::Signal_open()
{
    ui->lightButton_TX->setLightBlue();
}

void MainWindow::Signal_stop()
{
    ui->lightButton_TX->setGray();
}

void MainWindow::Signal_receive()
{
    ui->lightButton_TX->setGreen();
}


void MainWindow::SendData_go()
{
    int ID;
    ID = 0x029F3FF0;
    int ID1;
    ID1 = 0x02963FF0;
    QString Data = "0100000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
    emit SIGtocansen(ID1,vec);
    //qDebug()<<Data;
}

void MainWindow::SendData_group()
{
    int ID;
    ID = 0x02963FF0;
    QString Data = "0100000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
    //qDebug()<<Data;
}


void MainWindow::Vist_System_VA()
{
    int ID;
    ID = 0x02C101F0;
    QString Data = "0000000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist_Module_VA()
{
    int ID;
    ID = 0x02C301F0;
    QString Data = "0000000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist__VA1()
{
    int ID;
    ID = 0x028301F0;
    QString Data = "0000000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist_System_state()
{    
    int ID;
    ID = 0x02C401F0;
    QString Data = "0000000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist_state1()
{
    int ID;
    ID = 0x028401F0;
    QString Data = "0000000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist_System_module_Num()
{
    int ID;
    ID = 0x02C201F0;
    QString Data = "0000000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist_CEG1()
{
    int ID;
    ID = 0x028F01F0;
    QString Data = "1111010000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist_CEG2()
{
    int ID;
    ID = 0x028F02F0;
    QString Data = "1111010000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist_CEG3()
{
    int ID;
    ID = 0x028F03F0;
    QString Data = "1111010000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Vist_CEG4()
{
    int ID;
    ID = 0x028F04F0;
    QString Data = "1111010000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}


void MainWindow::on_btnStart_clicked()
{
    QMessageBox::StandardButton box;
    box = QMessageBox::question(this, "提示", "是否确定开机", QMessageBox::Yes|QMessageBox::No);
    //取消
    if(box==QMessageBox::No)
        return;
    //确认
    else if(box==QMessageBox::Yes)
    {        
        //qDebug()<<"exit null score";
        int ID;
        ID = 0x02DA01F0;
        QString Data = "0000000000000000";
        std::vector<int> vec;
        QByteArray data1 = Data.toUpper().toLatin1();
        for(int i=0; i<8; i++)
        {
            vec.push_back(Data.mid(2*i,2).toInt(0,16));
            double vec = QRandomGenerator::global()->generateDouble();
        }
        emit SIGtocansen(ID,vec);
        //ui->btnStart->setDisabled(true);
    }
}


void MainWindow::on_btnStop_clicked()
{
    int ID;
    ID = 0x02DA01F0;
    QString Data = "0100000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);

    QMessageBox msgbox;
    msgbox.setText("已关机");
    msgbox.setIcon(QMessageBox::Information);
    msgbox.setWindowTitle("提示");
    QTimer::singleShot(3000, &msgbox, &QMessageBox::close);
    msgbox.exec();
    ui->cc1state_le_4->setText("");
    ui->cc1state_le_5->setText("");
}

//CAN自动打开
void MainWindow::on_btnCan_clicked()
{
    emit SIGtocancon();
    //ui->lightButton_TX->setLightBlue();
}

void MainWindow::on_btnSendGo_clicked()
{
    int ID;
    ID = 0x029F3FF0;
    QString Data = "0200000000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
    m_Timer.start(1000);
}



void MainWindow::on_btnSet_clicked()
{
    if(ui->comboBox_all->currentIndex() == 0)
    {
        int ID;
        ID = 0x02DC01F0;
        int dataV = ui->cc1state_le_2->text().toInt();
        int dataA = ui->cc1state_le_3->text().toInt();
        QString strV = QString("%1").arg(dataV*1000, 8,16,QLatin1Char('0'));
        QString strA = QString("%1").arg(dataA*1000, 8,16,QLatin1Char('0'));
        //qDebug()<<strV+strA;
        Data_set = (strV+strA).toUpper();
        std::vector<int> vec;
        //QByteArray data1 = Data_set.toUpper().toLatin1();
        //qDebug()<<Data_set;
        for(int i=0; i<8; i++)
        {
            vec.push_back(Data_set.mid(2*i,2).toInt(0,16));
            double vec = QRandomGenerator::global()->generateDouble();
        }
        emit SIGtocansen(ID,vec);
    }
    else if(ui->comboBox_all->currentIndex() == 1)
    {
        int ID;
        ID = 0x02DB01F0;
        int dataV = ui->cc1state_le_2->text().toInt();
        int dataA = ui->cc1state_le_3->text().toInt();
        QString strV = QString("%1").arg(dataV*1000, 8,16,QLatin1Char('0'));
        QString strA = QString("%1").arg(dataA*1000, 8,16,QLatin1Char('0'));
        //qDebug()<<strV+strA;
        Data_set = (strV+strA).toUpper();
        std::vector<int> vec;
        //QByteArray data1 = Data_set.toUpper().toLatin1();
        //qDebug()<<Data_set;
        for(int i=0; i<8; i++)
        {
            vec.push_back(Data_set.mid(2*i,2).toInt(0,16));
            double vec = QRandomGenerator::global()->generateDouble();
        }
        emit SIGtocansen(ID,vec);
    }
}


void MainWindow::on_btnLightGreen_clicked()
{
    if(ui->btnLightGreen->text() == "休眠")
    {
        for(int i=0;i<5;i++)
        {
            int ID;
            ID = 0x02D901F0;
            QString Data = "0100000000000000";
            std::vector<int> vec;
            QByteArray data1 = Data.toUpper().toLatin1();
            for(int i=0; i<8; i++)
            {
                vec.push_back(Data.mid(2*i,2).toInt(0,16));
                double vec = QRandomGenerator::global()->generateDouble();
            }
            emit SIGtocansen(ID,vec);
        }
        ui->btnLightGreen->setText(tr("关闭休眠"));
    }
    else if(ui->btnLightGreen->text() == "关闭休眠")
    {
        for(int i=0;i<5;i++)
        {
            int ID;
            ID = 0x02D901F0;
            QString Data = "0000000000000000";
            std::vector<int> vec;
            QByteArray data1 = Data.toUpper().toLatin1();
            for(int i=0; i<8; i++)
            {
                vec.push_back(Data.mid(2*i,2).toInt(0,16));
                double vec = QRandomGenerator::global()->generateDouble();
            }
            emit SIGtocansen(ID,vec);
        }
        ui->btnLightGreen->setText(tr("休眠"));
    }
}


void MainWindow::on_btnWalkin_start_clicked()
{
    for(int i=0;i<5;i++)
    {
        int ID;
        ID = 0x02D301F0;
        QString Data = "0100000000000000";
        std::vector<int> vec;
        QByteArray data1 = Data.toUpper().toLatin1();
        for(int i=0; i<8; i++)
        {
            vec.push_back(Data.mid(2*i,2).toInt(0,16));
            double vec = QRandomGenerator::global()->generateDouble();
        }
        emit SIGtocansen(ID,vec);
    }
    //ui->lightButton_Walkin->setGreen();
}


void MainWindow::on_btnWalkin_stop_clicked()
{
    for(int i=0;i<5;i++)
    {
        int ID;
        ID = 0x02D301F0;
        QString Data = "0000000000000000";
        std::vector<int> vec;
        QByteArray data1 = Data.toUpper().toLatin1();
        for(int i=0; i<8; i++)
        {
            vec.push_back(Data.mid(2*i,2).toInt(0,16));
            double vec = QRandomGenerator::global()->generateDouble();
        }
        emit SIGtocansen(ID,vec);
    }
    //ui->lightButton_Walkin->setRed();
}

void MainWindow::mouseWheel()
{
    if (plot->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
        plot->axisRect()->setRangeZoom(plot->xAxis->orientation());
    else if (plot->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
        plot->axisRect()->setRangeZoom(plot->yAxis->orientation());
    else
        plot->axisRect()->setRangeZoom(Qt::Horizontal | Qt::Vertical);
}

//游标槽函数
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
    QCPGraph *mGraph = plot->graph();
    //曲线数量
    int graphCount=8;
    //获得鼠标位置处对应的横坐标数据x
    double x = plot->xAxis->pixelToCoord(event->pos().x());
    //遍历曲线
    for (int i = 0; i < graphCount; ++i)
    {
        //判断哪一条曲线被选中
        if(plot->graph(i)->selected())
        {
            //显示锚点
            tracer->setVisible(true);
            mGraph = plot->graph(i);

            tracer->setGraph(mGraph);//将锚点设置到被选中的曲线上
            //将像素点转换成qcustomplot中的坐标值，并通过setGraphKey将锚点值设为真实数据值。tracer->setGraphKey(xAxis->pixelToCoord(event->pos().x()));
            tracer->setGraphKey(x); //将游标横坐标设置成刚获得的横坐标数据x
            tracer->setInterpolating(true); //游标的纵坐标可以通过曲线数据线性插值自动获得
            tracer->updatePosition(); //使得刚设置游标的横纵坐标位置生效
            double xValue = tracer->position->key();
            double yValue = tracer->position->value();
            //显示tip框
            QToolTip::showText(event->globalPos(), tr(
                                   "<h4>%1</h4>"
                                   "<table>"
                                   "<tr>"
                                   "<td><h5>时间: %2</h5></td>" "<td> , </td>" "<td><h5>Value: %3</h5></td>"
                                   "</tr>"
                                   "</table>").arg(mGraph->name()).arg(QDateTime::fromMSecsSinceEpoch(xValue*1000.0).toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(QString::number(yValue,'f',2)), this, this->rect());
            break;
        }
        else
        {
            //没有曲线被选中，不显示锚点
            tracer->setVisible(false);
        }
    }
    //重绘
    plot->replot();
}


//图例选中图像槽函数
void MainWindow::selectionChanged()
{
    // synchronize selection of graphs with selection of corresponding legend items:
    for (int i=0; i<plot->graphCount(); ++i)
    {
        QCPGraph *graph = plot->graph(i);
        QCPPlottableLegendItem *item = plot->legend->itemWithPlottable(graph);

        if (item->selected())
        {
            item->setSelected(true);
            graph->setSelection(QCPDataSelection(graph->data()->dataRange()));
        }
        plot->update();
    }
}

void MainWindow::handleRightClick(QMouseEvent *event)
{
//    if (event->button() == Qt::RightButton) {
//        // 获取当前选中的曲线数据和坐标范围
//        QCPScatterSeries *series = qobject_cast<QCPScatterSeries*>(customPlotWidget->curves().at(0));
//        QRectF rect = customPlotWidget->viewport()->rect();

//        // 创建一个临时的QImage，用于绘制当前图形
//        QImage image(rect.size(), QImage::Format_RGB32);
//        QPainter painter(&image);
//        painter.setRenderHint(QPainter::Antialiasing); // 可选，开启抗锯齿

//        // 渲染图像
//        customPlotWidget->render(painter);

//        // 保存图像
//        QString savePath = "path_to_save/image_" + QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss") + ".png";
//        image.save(savePath);
//    }
}

//双击图例选择颜色函数
void MainWindow::when_legendDoubleClick (QCPLegend *legend, QCPAbstractLegendItem *legendItem, QMouseEvent *event)
{
    Q_UNUSED(legend);
    Q_UNUSED(event);
    //qDebug()<<"when_legendDoubleClick (QCPLegend *legend, QCPAbstractLegendItem *legendItem, QMouseEvent *event)";

    for (int i = 0; i < plot->graphCount(); ++i)
    {
        QCPGraph *pGraph1 = plot->graph(i);
        if(legendItem == plot->legend->itemWithPlottable(pGraph1))//查询被点击的图例项是哪个graph的图例项
        {
            QColor newColor = QColorDialog::getColor(Qt::red,this,"选择新颜色");
            if(newColor.isValid())//用户点击了确定
            {
                pGraph1->setPen(QPen(newColor,1));
                plot->replot(QCustomPlot::rpQueuedReplot);
            }
        }
    }
}

void MainWindow::on_btnCAN_clicked()
{    
    emit SIGtocancon();
}


void MainWindow::on_cc1state_le_2_cursorPositionChanged(int arg1, int arg2)
{

}


void MainWindow::on_btnfile_clicked()
{
    QPixmap pixmap = plot->toPixmap(1500, 800); // 将QCustomPlot转换为QPixmap
    QImage image=pixmap.toImage();
    // 获取程序运行路径
    QString savePath = QCoreApplication::applicationDirPath() + "/LineImage";
    // 判断文件路径
    if (isDirExist(savePath)) {
    } else {
        qDebug() << "保存文件目录未找到!";
        QMessageBox::warning(this,
                             "warning",
                             "保存文件目录未找到!",
                             QMessageBox::Yes,
                             QMessageBox::Yes);
    }
    QString fileName = QFileDialog::getSaveFileName(this,
                                                    "保存波形数据",                    // 对话框的标题
                                                    savePath,                        // 保存的默认路径为程序运行路径
                                                    "Save Picture (*.png *jpg)");    // 打开文件的类型，;隔开
    // 如果用户点击了“取消”按钮
    if (fileName.isNull())
        return;
    image.save(fileName);
}

//文件路径函数
bool MainWindow::isDirExist(QString fullPath)
{
    QDir dir(fullPath);
    if(dir.exists()) {
        return true;
    } else {
        // 创建一级子目录，必须保证上级目录存在
        bool ok = dir.mkdir(fullPath);
        return ok;
    }
}

void MainWindow::on_btnMPPT_clicked()
{
    int ID;
    ID = 0x028F3FF0;
    QString Data = "11110000000000A1";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}


void MainWindow::on_btnSRHY_clicked()
{
    int ID;
    ID = 0x028F3FF0;
    QString Data = "11110000000000A2";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

